// components/diy/picturew/index.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    diyPramas:{
      type:Object
    },
    diyStyle:{
      type:Object
    },
    diyData:{
      type:Object
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    swiperCurrent: 0,
    slider:[],
    swiperBtnHeight:0, //图组高度
    lineSize:0, //行数
    pageSize:0,  //页数
    num:0
  },

  /**
   * 组件的方法列表
   */
  methods: {
    //轮播图的切换事件
    swiperChange: function(e){
      //只要把切换后当前的index传给<swiper>组件的current属性即可
      this.setData({
        swiperCurrent: e.detail.current
      })
    },

    //点击指示点切换
    chuangEvent: function(e){
      this.setData({
        swiperCurrent: e.currentTarget.id
      })
    }
  },

  ready: function(){
    var num = this.data.diyData.length; //总共图片数
    var pagenum = this.properties.diyStyle.pagenum; //每页显示个数
    var rownum = this.properties.diyPramas.row; //每行显示个数
    var pageSize = 0;//总共页数
    this.setData({
      num: num
    })
    if(rownum != '1'){
      if(num%pagenum == 0){
        pageSize = parseInt(num/pagenum)
      }else{
        pageSize = parseInt(num/pagenum) + 1
      }
      var lineSize = 1;//每页行数
      /**
       * 堆积两列 每页最多四张
       * 堆积三列 每页最多七张
       * 堆积四列 每页最多十张
      */
      var showtype = this.properties.diyPramas.showtype
      var row = this.properties.diyPramas.row
      if((row == 2 ||  row == 3  || row == 4)  && showtype == 1){
        var that = this
        var query = wx.createSelectorQuery().in(this)
        query.select('.sliding').boundingClientRect((rect) => {
          var width = rect.width;
          var paddingleft = that.properties.diyStyle.paddingleft
          var paddingtop = that.properties.diyStyle.paddingtop
          var imageHeight = (width - paddingleft*2*rownum  - 2*paddingleft )/rownum
          var height = imageHeight * lineSize + paddingtop * (2 * lineSize)
          this.setData({
            swiperBtnHeight: height
          })
        }).exec()
        this.setData({
          pageSize:pageSize,
          lineSize:lineSize
        }) 
      }
      
    }
  }
})
